package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.domain.UserCaseDO;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.DeleteGroup;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.UpdateGroup;
import com.feisuanyz.lyweb01.pojo.dto.UserCaseDTO;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.query.UserCaseQuery;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.UserCaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户案例
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "用户案例")
@RequestMapping("user_case")
@RestController
public class UserCaseController {

    @Autowired
    private UserCaseService userCaseService;

    /**
     * 获取用户案例列表
     *
     * @param userCaseQuery 用户案例查询对象
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "获取用户案例列表")
    public RestResult<PageResult<UserCaseDO>> getUserCaseList(@Validated(QueryGroup.class) UserCaseQuery userCaseQuery) {
        PageResult<UserCaseDO> result = userCaseService.getUserCaseList(userCaseQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取用户案例详情
     *
     * @param userCaseQuery 用户案例查询对象
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @Operation(summary = "获取用户案例详情")
    public RestResult<UserCaseDO> getUserCaseDetail(@Validated(QueryGroup.class) UserCaseQuery userCaseQuery) {
        UserCaseDO result = userCaseService.getUserCaseDetail(userCaseQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 创建用户案例
     *
     * @param userCaseDTO 用户案例数据传输对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "创建用户案例")
    @ResponseBody
    public RestResult<Boolean> addUserCase(@RequestBody @Validated(CreateGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.addUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 更新用户案例
     *
     * @param userCaseDTO 用户案例数据传输对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "更新用户案例")
    @ResponseBody
    public RestResult<Boolean> updateUserCase(@RequestBody @Validated(UpdateGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.updateUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除用户案例
     *
     * @param userCaseDTO 用户案例数据传输对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.PUT)
    @Operation(summary = "删除用户案例")
    @ResponseBody
    public RestResult<Boolean> deleteUserCase(@RequestBody @Validated(DeleteGroup.class) UserCaseDTO userCaseDTO) {
        Boolean result = userCaseService.deleteUserCase(userCaseDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
